package com.wajahatkarim3.rdbexplorer.slice.dialog;

import com.wajahatkarim3.rdbexplorer.ResourceTable;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.Text;
import ohos.agp.window.dialog.CommonDialog;
import ohos.app.Context;

/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
public class ConfirmDialog extends CommonDialog implements Component.ClickedListener {

    private Context context;
    private String title;
    private String message;
    private int[] size;
    private ConfirmdialogListener listener;
    private Component layout;


    public ConfirmDialog(Context context, ConfirmdialogListener listener, String title, String message) {
        super(context);
        this.context = context;
        this.title = title;
        this.message = message;
        this.listener=listener;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        layout = LayoutScatter.getInstance(context).
                parse(ResourceTable.Layout_confirm_dialog, null, true);
        setTransparent(true);
        setContentCustomComponent(layout);
        initView();
    }

    private void initView() {
        Button cancelbtn= (Button) layout.findComponentById(ResourceTable.Id_confirm_cancel_btn);
        Button affirmbtn= (Button) layout.findComponentById(ResourceTable.Id_confirm_affirm_btn);
        Text title = (Text) layout.findComponentById(ResourceTable.Id_dialog_title);
        Text message = (Text) layout.findComponentById(ResourceTable.Id_dialog_message);
        title.setText(this.title);
        message.setText(this.message);
        cancelbtn.setClickedListener(this);
        affirmbtn.setClickedListener(this);
    }

    @Override
    public void onClick(Component component) {
        if (component.getId() == ResourceTable.Id_confirm_affirm_btn) {
            listener.getClickStatus(true);
        } else {
            listener.getClickStatus(false);
        }
        ConfirmDialog.this.destroy();
    }
}
